<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Board/pca10001/ble/ble_app_hrs/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('pca10001_2ble_2ble__app__hrs_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Board/pca10001/ble/ble_app_hrs/main.c</div>  </div>
</div>
<div class="contents">
<a href="pca10001_2ble_2ble__app__hrs_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;nrf.h&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="nrf__assert_8h.html" title="Utilities for verifying program logic.">nrf_assert.h</a>&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;nrf51_bitfields.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;ble.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;<a class="code" href="ble__advdata_8h.html">ble_advdata.h</a>&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="ble__bas_8h.html">ble_bas.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="ble__hrs_8h.html">ble_hrs.h</a>&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="ble__dis_8h.html">ble_dis.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="ble__eval__board__pins_8h.html">ble_eval_board_pins.h</a>&quot;</span> 
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="ble__sensorsim_8h.html">ble_sensorsim.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="ble__stack__handler_8h.html">ble_stack_handler.h</a>&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00045"></a>00045 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00046"></a>00046 <span class="preprocessor">#include &quot;nrf_gpiote.h&quot;</span>
<a name="l00047"></a>00047 
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">00049</a> <span class="preprocessor">#define DEVICE_NAME                          &quot;HRS_EVAL&quot;                                </span>
<a name="l00050"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaaa2b8f5b105c3019df0cb346f472e803">00050</a> <span class="preprocessor">#define MANUFACTURER_NAME                    &quot;NordicSemiconductor&quot;                     </span>
<a name="l00051"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">00051</a> <span class="preprocessor">#define APP_ADV_INTERVAL                     40                                        </span>
<a name="l00052"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf58371bad8e1be8e2323df60379ed2df">00052</a> <span class="preprocessor">#define APP_ADV_TIMEOUT_IN_SECONDS           180                                       </span>
<a name="l00054"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">00054</a> <span class="preprocessor">#define BATTERY_LEVEL_MEAS_INTERVAL          2000                                      </span>
<a name="l00055"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga59eb06cba38be11278ebd2829e95bc26">00055</a> <span class="preprocessor">#define MIN_BATTERY_LEVEL                    81                                        </span>
<a name="l00056"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga16896fb7a69ca90a4a4e341d5a888002">00056</a> <span class="preprocessor">#define MAX_BATTERY_LEVEL                    100                                       </span>
<a name="l00057"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga69eef02165834e4dabc5757b82dddbf1">00057</a> <span class="preprocessor">#define BATTERY_LEVEL_INCREMENT              1                                         </span>
<a name="l00059"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga45a3c3dc5dec56bf2ed3d1c4fdb0ccdd">00059</a> <span class="preprocessor">#define HEART_RATE_MEAS_INTERVAL             1000                                      </span>
<a name="l00060"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">00060</a> <span class="preprocessor">#define MIN_HEART_RATE                       60                                        </span>
<a name="l00061"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5c6a36078512a923ab07d1b8276c8cca">00061</a> <span class="preprocessor">#define MAX_HEART_RATE                       100                                       </span>
<a name="l00062"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab604f2d2e09476706dece4ba10d23083">00062</a> <span class="preprocessor">#define HEART_RATE_CHANGE                    2                                         </span>
<a name="l00064"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga77ece330b6222b510f509e25282874b0">00064</a> <span class="preprocessor">#define HR_INC_BUTTON_PIN_NO                 EVAL_BOARD_BUTTON_0                       </span>
<a name="l00065"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5713bbcd7b63f0a3fa11eb22f08417ff">00065</a> <span class="preprocessor">#define HR_DEC_BUTTON_PIN_NO                 EVAL_BOARD_BUTTON_1                       </span>
<a name="l00067"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga95196d5d0f40cf195a6001955d6d98cf">00067</a> <span class="preprocessor">#define MIN_CONN_INTERVAL                    ((1 * 800) / 2)                           </span>
<a name="l00068"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7d868ed8adb7d475b463fd8855907a18">00068</a> <span class="preprocessor">#define MAX_CONN_INTERVAL                    (1 * 800)                                 </span>
<a name="l00069"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga0c921a874ac37870fc1516ce66cd228a">00069</a> <span class="preprocessor">#define SLAVE_LATENCY                        0                                         </span>
<a name="l00070"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga799412c2b531ca347e13611e6e7523b9">00070</a> <span class="preprocessor">#define CONN_SUP_TIMEOUT                     (4 * 100)                                 </span>
<a name="l00071"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">00071</a> <span class="preprocessor">#define FIRST_CONN_PARAMS_UPDATE_DELAY       5000                                      </span>
<a name="l00072"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadf85796ef07632ed27e0bce9509d9245">00072</a> <span class="preprocessor">#define NEXT_CONN_PARAMS_UPDATE_DELAY        5000                                      </span>
<a name="l00073"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">00073</a> <span class="preprocessor">#define MAX_CONN_PARAMS_UPDATE_COUNT         3                                         </span>
<a name="l00075"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7c1fffb0f865552108560d4c63b32db1">00075</a> <span class="preprocessor">#define SEC_PARAM_TIMEOUT                    60                                        </span>
<a name="l00076"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacbf03a82593c273743a5a80a1119b851">00076</a> <span class="preprocessor">#define SEC_PARAM_BOND                       1                                         </span>
<a name="l00077"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab6831ebe113f8afe970326b7742b5947">00077</a> <span class="preprocessor">#define SEC_PARAM_MITM                       0                                         </span>
<a name="l00078"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga42df85b3a4083cdc614d9111d580d98f">00078</a> <span class="preprocessor">#define SEC_PARAM_IO_CAPABILITIES            BLE_GAP_IO_CAPS_NONE                      </span>
<a name="l00079"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">00079</a> <span class="preprocessor">#define SEC_PARAM_OOB                        0                                         </span>
<a name="l00080"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">00080</a> <span class="preprocessor">#define SEC_PARAM_MIN_KEY_SIZE               7                                         </span>
<a name="l00081"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf2cd1595de153ea1d6d843619a1a7707">00081</a> <span class="preprocessor">#define SEC_PARAM_MAX_KEY_SIZE               16                                        </span>
<a name="l00083"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga0dbd98cbb765458f7fd9e1b493f06414">00083</a> <span class="preprocessor">#define ADC_REF_VOLTAGE_IN_MILLIVOLTS        1200                                      </span>
<a name="l00084"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa9d35b437e029827df8e9c026d3b4ebe">00084</a> <span class="preprocessor">#define ADC_PRE_SCALING_COMPENSATION         3                                         </span>
<a name="l00085"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga66573611a61405487b66c513f0662c45">00085</a> <span class="preprocessor">#define DIODE_FWD_VOLT_DROP_MILLIVOLTS       270                                       </span>
<a name="l00086"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga86b4a9059f88ccc1bc39a767ab2d1dc3">00086</a> <span class="preprocessor">#define TOTAL_NUMBER_OF_IO_PINS              32                                        </span>
<a name="l00088"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga80f81a2f3b5f5e1642c38bf65eeaedf1">00088</a> <span class="preprocessor">#define PPI_CHAN0_TO_TOGGLE_LED              0                                         </span>
<a name="l00089"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga9bd321ef3347adb74670b3bd22ed5967">00089</a> <span class="preprocessor">#define PPI_CHAN1_TO_TOGGLE_LED              1                                         </span>
<a name="l00091"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga79bf7625596d78764844d19ef2a59021">00091</a> <span class="preprocessor">#define GPIOTE_CHAN_FOR_LED_TASK             0                                         </span>
<a name="l00093"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa7914b8d7fd0bae056b85acb5062676b">00093</a> <span class="preprocessor">#define TIMER_PRESCALER                      9                                         </span>
<a name="l00094"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf5c81cd7fdbb7fdce40872b70c95067b">00094</a> <span class="preprocessor">#define CAPTURE_COMPARE_0_VALUE              0x1E84                                    </span>
<a name="l00095"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8f1d7e1291660f2db78dcc504ad588ec">00095</a> <span class="preprocessor">#define CAPTURE_COMPARE_1_VALUE              (CAPTURE_COMPARE_0_VALUE * 2)             </span>
<a name="l00097"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">00097</a> <span class="preprocessor">static ble_gap_sec_params_t                  s_sec_params;                             </span>
<a name="l00098"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">00098</a> <span class="preprocessor">static ble_gap_adv_params_t                  s_adv_params;                             </span>
<a name="l00099"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">00099</a> <span class="preprocessor">static ble_bas_t                             s_bas;                                    </span>
<a name="l00100"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">00100</a> <span class="preprocessor">static ble_hrs_t                             s_hrs;                                    </span>
<a name="l00101"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">00101</a> <span class="preprocessor">static volatile uint16_t                     s_cur_heart_rate;                         </span>
<a name="l00109"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga0552bb76e072f5519938dfdb8b9b8b03">00109</a> <span class="preprocessor">#define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)\</span>
<a name="l00110"></a>00110 <span class="preprocessor">        ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 255) * ADC_PRE_SCALING_COMPENSATION)</span>
<a name="l00111"></a>00111 <span class="preprocessor"></span>
<a name="l00112"></a>00112 
<a name="l00120"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadec561788a76b8a63ad9663625a25d78">00120</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#gadec561788a76b8a63ad9663625a25d78" title="Assert macro callback function.">assert_nrf_callback</a>(uint16_t line_num, <span class="keyword">const</span> uint8_t * file_name)
<a name="l00121"></a>00121 {
<a name="l00122"></a>00122     <span class="comment">// Copying parameters to static variables because parameters are not accessible in debugger</span>
<a name="l00123"></a>00123     <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t  s_file_name[128];
<a name="l00124"></a>00124     <span class="keyword">static</span> <span class="keyword">volatile</span> uint16_t s_line_num;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126     strcpy((<span class="keywordtype">char</span> *)s_file_name, (<span class="keyword">const</span> <span class="keywordtype">char</span> *)file_name);
<a name="l00127"></a>00127     s_line_num = line_num;
<a name="l00128"></a>00128     UNUSED_VARIABLE(s_file_name);
<a name="l00129"></a>00129     UNUSED_VARIABLE(s_line_num);
<a name="l00130"></a>00130     
<a name="l00131"></a>00131     <span class="keywordflow">for</span> (;;)
<a name="l00132"></a>00132     {
<a name="l00133"></a>00133         <span class="comment">// Loop forever. On assert, the system can only recover on reset</span>
<a name="l00134"></a>00134     }
<a name="l00135"></a>00135 }
<a name="l00136"></a>00136 
<a name="l00137"></a>00137 
<a name="l00141"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga57efeb20271786f1b6db8bdb4b1d0ee4">00141</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga57efeb20271786f1b6db8bdb4b1d0ee4" title="Update the given Battery Level characteristic in Battery Service.">battery_level_update</a>(<span class="keyword">const</span> uint8_t battery_level)
<a name="l00142"></a>00142 {
<a name="l00143"></a>00143     uint32_t err_code;
<a name="l00144"></a>00144 
<a name="l00145"></a>00145     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#ga58d8f4336cce49ea5b3a2f8997bfe00e" title="Update battery level.">ble_bas_battery_level_update</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, battery_level);
<a name="l00146"></a>00146     <span class="keywordflow">if</span> (
<a name="l00147"></a>00147         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00148"></a>00148         &amp;&amp;
<a name="l00149"></a>00149         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00150"></a>00150         &amp;&amp;
<a name="l00151"></a>00151         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00152"></a>00152         &amp;&amp;
<a name="l00153"></a>00153         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00154"></a>00154     )
<a name="l00155"></a>00155     {
<a name="l00156"></a>00156         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00157"></a>00157     }
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 
<a name="l00163"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa8ab696faf261604569b426bdbd6a199">00163</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa8ab696faf261604569b426bdbd6a199" title="Function to make the ADC start a conversion.">adc_start</a>(<span class="keywordtype">void</span>)
<a name="l00164"></a>00164 {
<a name="l00165"></a>00165     NRF_ADC-&gt;EVENTS_END  = 0;    <span class="comment">// Stop any running conversions.</span>
<a name="l00166"></a>00166     NRF_ADC-&gt;TASKS_START = 1;
<a name="l00167"></a>00167 }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169 
<a name="l00177"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155">00177</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00178"></a>00178 {
<a name="l00179"></a>00179     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_BATTERY_LEVEL_MEAS);
<a name="l00180"></a>00180     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa8ab696faf261604569b426bdbd6a199" title="Function to make the ADC start a conversion.">adc_start</a>();
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183 
<a name="l00191"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b">00191</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b" title="Heart rate measurement timer timeout handler.">heart_rate_meas_timeout_handler</a>(app_timer_id_t timer_id)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193     uint32_t err_code;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(timer_id == APP_TIMER_HEART_RATE_MEAS);
<a name="l00196"></a>00196 
<a name="l00197"></a>00197     err_code = <a class="code" href="group__ble__sdk__srv__hrs.html#gabe5fed48baeb4a518a51bd7e2e5f010e" title="Sends heart rate measurement if notification has been enabled.">ble_hrs_heart_rate_measurement_send</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a>);
<a name="l00198"></a>00198     <span class="keywordflow">if</span> (
<a name="l00199"></a>00199         (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00200"></a>00200         &amp;&amp;
<a name="l00201"></a>00201         (err_code != <a class="code" href="group__nrf__error.html#gaf0aff2ba7864b34a36b4a96986e1851e" title="Invalid state, operation disallowed in this state.">NRF_ERROR_INVALID_STATE</a>)
<a name="l00202"></a>00202         &amp;&amp;
<a name="l00203"></a>00203         (err_code != <a class="code" href="group__ble__err.html#ga901e1bc3ccae29eff9fb31cabdbb5e02">BLE_ERROR_NO_TX_BUFFERS</a>)
<a name="l00204"></a>00204         &amp;&amp;
<a name="l00205"></a>00205         (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
<a name="l00206"></a>00206     )
<a name="l00207"></a>00207     {
<a name="l00208"></a>00208         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00209"></a>00209     }
<a name="l00210"></a>00210 }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 <span class="comment">/* @brief ADC Initialisation function.</span>
<a name="l00214"></a>00214 <span class="comment"> *</span>
<a name="l00215"></a>00215 <span class="comment"> * @details This function will initialise the ADC.</span>
<a name="l00216"></a>00216 <span class="comment"> */</span>
<a name="l00217"></a>00217 <span class="keyword">static</span> <span class="keywordtype">void</span> adc_init()
<a name="l00218"></a>00218 {
<a name="l00219"></a>00219     uint32_t err_code;
<a name="l00220"></a>00220     uint32_t per_rdy;
<a name="l00221"></a>00221 
<a name="l00222"></a>00222     <span class="comment">// Power on ADC module</span>
<a name="l00223"></a>00223     err_code = <a class="code" href="group__nrf__soc__api.html#ga4070a6cd178fce204f58a1bf6e3fc954" title="Sets bits in the NRF_POWER-&gt;PERPOWER register.">nrf_power_perpower_set</a>(POWER_PERPOWER_ADC_Msk);
<a name="l00224"></a>00224     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00225"></a>00225     {
<a name="l00226"></a>00226         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00227"></a>00227     }
<a name="l00228"></a>00228 
<a name="l00229"></a>00229     <span class="comment">// Wait for the power up of the ADC</span>
<a name="l00230"></a>00230     <span class="keywordflow">do</span>
<a name="l00231"></a>00231     {
<a name="l00232"></a>00232         err_code = <a class="code" href="group__nrf__soc__api.html#gabaf2aa42d1d287d9d4fd2b00ecda1da7" title="Get contents of NRF_POWER-&gt;PERRDY register, indicates which peripherals are powered on/off...">nrf_power_perrdy_get</a>(&amp;per_rdy);
<a name="l00233"></a>00233         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00234"></a>00234         {
<a name="l00235"></a>00235             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00236"></a>00236         }
<a name="l00237"></a>00237     } <span class="keywordflow">while</span> ((per_rdy &amp; POWER_PERPOWER_ADC_Msk) == 0);
<a name="l00238"></a>00238     
<a name="l00239"></a>00239     <span class="comment">// Configure ADC</span>
<a name="l00240"></a>00240     NRF_ADC-&gt;INTENSET   = ADC_INTENSET_END_Msk;
<a name="l00241"></a>00241     NRF_ADC-&gt;CONFIG     = (ADC_CONFIG_RES_8bit                        &lt;&lt; ADC_CONFIG_RES_Pos)     |
<a name="l00242"></a>00242                           (ADC_CONFIG_INPSEL_SupplyOneThirdPrescaling &lt;&lt; ADC_CONFIG_INPSEL_Pos)  |
<a name="l00243"></a>00243                           (ADC_CONFIG_REFSEL_VBG                      &lt;&lt; ADC_CONFIG_REFSEL_Pos)  |
<a name="l00244"></a>00244                           (ADC_CONFIG_PSEL_Disabled                   &lt;&lt; ADC_CONFIG_PSEL_Pos)    |
<a name="l00245"></a>00245                           (ADC_CONFIG_EXTREFSEL_None                  &lt;&lt; ADC_CONFIG_EXTREFSEL_Pos);
<a name="l00246"></a>00246     NRF_ADC-&gt;EVENTS_END = 0;                        
<a name="l00247"></a>00247     NRF_ADC-&gt;ENABLE     = ADC_ENABLE_ENABLE_Enabled;
<a name="l00248"></a>00248     
<a name="l00249"></a>00249     <span class="comment">// Enable ADC interrupt</span>
<a name="l00250"></a>00250     err_code = <a class="code" href="group__nrf__soc__api.html#ga444796a3a1fc91db087ceebcd92d6561" title="Clear Pending Interrupt.">nrf_nvic_ClearPendingIRQ</a>(ADC_IRQn);
<a name="l00251"></a>00251     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00252"></a>00252     {
<a name="l00253"></a>00253         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00254"></a>00254     }
<a name="l00255"></a>00255 
<a name="l00256"></a>00256     err_code = <a class="code" href="group__nrf__soc__api.html#gad1a939313c86ac881a0b1043715ef475" title="Set Interrupt Priority.">nrf_nvic_SetPriority</a>(ADC_IRQn, NRF_APP_PRIORITY_LOW);
<a name="l00257"></a>00257     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00258"></a>00258     {
<a name="l00259"></a>00259         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261     
<a name="l00262"></a>00262     err_code = <a class="code" href="group__nrf__soc__api.html#ga624ecb710ec5cdaf22893608d55c6f3a" title="Enable External Interrupt.">nrf_nvic_EnableIRQ</a>(ADC_IRQn);
<a name="l00263"></a>00263     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00264"></a>00264     {
<a name="l00265"></a>00265         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00266"></a>00266     }
<a name="l00267"></a>00267 }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269 
<a name="l00270"></a>00270 <span class="comment">/* @brief Timer 1 initialisation function.</span>
<a name="l00271"></a>00271 <span class="comment"> *</span>
<a name="l00272"></a>00272 <span class="comment"> * @details This function will initialise Timer 1 peripheral. This timer is used only to</span>
<a name="l00273"></a>00273 <span class="comment"> *          generate capture compare events that toggle the advertising LED state.</span>
<a name="l00274"></a>00274 <span class="comment"> */</span>
<a name="l00275"></a>00275 <span class="keyword">static</span> <span class="keywordtype">void</span> timer1_init(<span class="keywordtype">void</span>)
<a name="l00276"></a>00276 {
<a name="l00277"></a>00277     uint32_t err_code;
<a name="l00278"></a>00278     uint32_t per_rdy;
<a name="l00279"></a>00279 
<a name="l00280"></a>00280     <span class="comment">// Power on the TIMER1 peripheral</span>
<a name="l00281"></a>00281     err_code = <a class="code" href="group__nrf__soc__api.html#ga4070a6cd178fce204f58a1bf6e3fc954" title="Sets bits in the NRF_POWER-&gt;PERPOWER register.">nrf_power_perpower_set</a>(POWER_PERPOWER_TIMER1_Msk);
<a name="l00282"></a>00282     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00283"></a>00283     {
<a name="l00284"></a>00284         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00285"></a>00285     }
<a name="l00286"></a>00286 
<a name="l00287"></a>00287     <span class="comment">// Wait for the power up of TIMER1</span>
<a name="l00288"></a>00288     <span class="keywordflow">do</span>
<a name="l00289"></a>00289     {
<a name="l00290"></a>00290         err_code = <a class="code" href="group__nrf__soc__api.html#gabaf2aa42d1d287d9d4fd2b00ecda1da7" title="Get contents of NRF_POWER-&gt;PERRDY register, indicates which peripherals are powered on/off...">nrf_power_perrdy_get</a>(&amp;per_rdy);
<a name="l00291"></a>00291         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00292"></a>00292         {
<a name="l00293"></a>00293             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00294"></a>00294         }
<a name="l00295"></a>00295     } <span class="keywordflow">while</span> ((per_rdy &amp; POWER_PERPOWER_TIMER1_Msk) == 0);
<a name="l00296"></a>00296 
<a name="l00297"></a>00297     <span class="comment">// Configure timer</span>
<a name="l00298"></a>00298     NRF_TIMER1-&gt;MODE      = TIMER_MODE_MODE_Timer;
<a name="l00299"></a>00299     NRF_TIMER1-&gt;BITMODE   = TIMER_BITMODE_BITMODE_16Bit;
<a name="l00300"></a>00300     NRF_TIMER1-&gt;PRESCALER = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa7914b8d7fd0bae056b85acb5062676b">TIMER_PRESCALER</a>;
<a name="l00301"></a>00301 
<a name="l00302"></a>00302     <span class="comment">// Clear the timer</span>
<a name="l00303"></a>00303     NRF_TIMER1-&gt;TASKS_CLEAR = 1;
<a name="l00304"></a>00304 
<a name="l00305"></a>00305     <span class="comment">// Load the values to TIMER1 CC registers. The following values are calculated for generating</span>
<a name="l00306"></a>00306     <span class="comment">// a 2 Hz waveform that will serve as input to the LED.</span>
<a name="l00307"></a>00307     NRF_TIMER1-&gt;CC[0] = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf5c81cd7fdbb7fdce40872b70c95067b">CAPTURE_COMPARE_0_VALUE</a>;
<a name="l00308"></a>00308     NRF_TIMER1-&gt;CC[1] = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8f1d7e1291660f2db78dcc504ad588ec">CAPTURE_COMPARE_1_VALUE</a>;
<a name="l00309"></a>00309 
<a name="l00310"></a>00310     <span class="comment">// Make the Capture Compare 1 event to clear the timer. This will restart the timer.</span>
<a name="l00311"></a>00311     NRF_TIMER1-&gt;SHORTS = TIMER_SHORTS_COMPARE1_CLEAR_Enabled &lt;&lt; TIMER_SHORTS_COMPARE1_CLEAR_Pos;
<a name="l00312"></a>00312 
<a name="l00313"></a>00313     <span class="comment">// There is no need to setup NRF_TIMER1-&gt;INTENSET register because the application do not need</span>
<a name="l00314"></a>00314     <span class="comment">// to wake up the CPU on Timer interrupts.</span>
<a name="l00315"></a>00315 }
<a name="l00316"></a>00316 
<a name="l00317"></a>00317 
<a name="l00318"></a>00318 <span class="comment">/* @brief PPI initialisation function.</span>
<a name="l00319"></a>00319 <span class="comment"> *</span>
<a name="l00320"></a>00320 <span class="comment"> * @details This function will initialise Programmable Peripheral Interconnect peripheral. It will</span>
<a name="l00321"></a>00321 <span class="comment"> *          configure the PPI channels as follows -</span>
<a name="l00322"></a>00322 <span class="comment"> *              PPI Channel 0 - Connecting CC0 Compare event to GPIOTE Task to toggle the LED state</span>
<a name="l00323"></a>00323 <span class="comment"> *              PPI Channel 1 - Connecting CC1 Compare event to GPIOTE Task to toggle the LED state</span>
<a name="l00324"></a>00324 <span class="comment"> *          This configuration will feed a PWM input to the LED thereby making it flash in an</span>
<a name="l00325"></a>00325 <span class="comment"> *          interval that is dependent on the TIMER configuration.</span>
<a name="l00326"></a>00326 <span class="comment"> */</span>
<a name="l00327"></a>00327 <span class="keyword">static</span> <span class="keywordtype">void</span> ppi_init(<span class="keywordtype">void</span>)
<a name="l00328"></a>00328 {
<a name="l00329"></a>00329     uint32_t err_code;
<a name="l00330"></a>00330 
<a name="l00331"></a>00331     <span class="comment">// Configure PPI channel 0 to toggle ADVERTISING_LED_PIN_NO on every TIMER1 COMPARE[0] match</span>
<a name="l00332"></a>00332     err_code = <a class="code" href="group__nrf__soc__api.html#ga36d104cdb021a86c919485ac34c48fa2" title="Assign endpoints to a PPI channel.">nrf_ppi_channel_assign</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga80f81a2f3b5f5e1642c38bf65eeaedf1">PPI_CHAN0_TO_TOGGLE_LED</a>,
<a name="l00333"></a>00333                                      &amp;(NRF_TIMER1-&gt;EVENTS_COMPARE[0]),
<a name="l00334"></a>00334                                      &amp;(NRF_GPIOTE-&gt;TASKS_OUT[0]));
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00336"></a>00336     {
<a name="l00337"></a>00337         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00338"></a>00338     }
<a name="l00339"></a>00339 
<a name="l00340"></a>00340     <span class="comment">// Configure PPI channel 1 to toggle ADVERTISING_LED_PIN_NO on every TIMER1 COMPARE[1] match</span>
<a name="l00341"></a>00341     err_code = <a class="code" href="group__nrf__soc__api.html#ga36d104cdb021a86c919485ac34c48fa2" title="Assign endpoints to a PPI channel.">nrf_ppi_channel_assign</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga9bd321ef3347adb74670b3bd22ed5967">PPI_CHAN1_TO_TOGGLE_LED</a>,
<a name="l00342"></a>00342                                       &amp;(NRF_TIMER1-&gt;EVENTS_COMPARE[1]),
<a name="l00343"></a>00343                                       &amp;(NRF_GPIOTE-&gt;TASKS_OUT[0]));
<a name="l00344"></a>00344     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00345"></a>00345     {
<a name="l00346"></a>00346         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00347"></a>00347     }
<a name="l00348"></a>00348 
<a name="l00349"></a>00349     <span class="comment">// Enable the PPI channels 0, 1 and 2 thereby connecting the TIMER compare events to the GPIOTE</span>
<a name="l00350"></a>00350     <span class="comment">// task that toggles the LED.</span>
<a name="l00351"></a>00351     err_code = <a class="code" href="group__nrf__soc__api.html#gad18f79c96963c57714cf30b5922fe8e5" title="Set PPI channel enable register.">nrf_ppi_channel_enable_set</a>(PPI_CHEN_CH0_Msk | PPI_CHEN_CH1_Msk);
<a name="l00352"></a>00352     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00353"></a>00353     {
<a name="l00354"></a>00354         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00355"></a>00355     }
<a name="l00356"></a>00356 }
<a name="l00357"></a>00357 
<a name="l00358"></a>00358 
<a name="l00363"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad22626704ea5d45f863163500e355cc3">00363</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad22626704ea5d45f863163500e355cc3" title="Initialize GPIOTE module.">gpiote_init</a>(<span class="keywordtype">void</span>)
<a name="l00364"></a>00364 {
<a name="l00365"></a>00365     uint32_t err_code;
<a name="l00366"></a>00366     uint32_t per_rdy;
<a name="l00367"></a>00367 
<a name="l00368"></a>00368     <span class="comment">// Power on GPIOTE module</span>
<a name="l00369"></a>00369     err_code = <a class="code" href="group__nrf__soc__api.html#ga4070a6cd178fce204f58a1bf6e3fc954" title="Sets bits in the NRF_POWER-&gt;PERPOWER register.">nrf_power_perpower_set</a>(POWER_PERPOWER_GPIOTE_Msk);
<a name="l00370"></a>00370     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00371"></a>00371     {
<a name="l00372"></a>00372         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00373"></a>00373     }
<a name="l00374"></a>00374 
<a name="l00375"></a>00375     <span class="keywordflow">do</span>
<a name="l00376"></a>00376     {
<a name="l00377"></a>00377         err_code = <a class="code" href="group__nrf__soc__api.html#gabaf2aa42d1d287d9d4fd2b00ecda1da7" title="Get contents of NRF_POWER-&gt;PERRDY register, indicates which peripherals are powered on/off...">nrf_power_perrdy_get</a>(&amp;per_rdy);
<a name="l00378"></a>00378         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00379"></a>00379         {
<a name="l00380"></a>00380             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00381"></a>00381         }
<a name="l00382"></a>00382     } <span class="keywordflow">while</span> ((per_rdy &amp; POWER_PERPOWER_GPIOTE_Msk) == 0);
<a name="l00383"></a>00383 
<a name="l00384"></a>00384     <span class="comment">// Initialize GPIOTE module</span>
<a name="l00385"></a>00385     NRF_GPIOTE-&gt;INTENCLR     = 0xffffffffUL;
<a name="l00386"></a>00386     NRF_GPIOTE-&gt;INTENSET     = GPIOTE_INTENSET_PORT_Msk; <span class="comment">// To receive button presses as PORT event</span>
<a name="l00387"></a>00387 
<a name="l00388"></a>00388     <span class="comment">// Enable GPIOTE interrupt</span>
<a name="l00389"></a>00389     err_code = <a class="code" href="group__nrf__soc__api.html#ga444796a3a1fc91db087ceebcd92d6561" title="Clear Pending Interrupt.">nrf_nvic_ClearPendingIRQ</a>(GPIOTE_IRQn);
<a name="l00390"></a>00390     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00391"></a>00391     {
<a name="l00392"></a>00392         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00393"></a>00393     }
<a name="l00394"></a>00394 
<a name="l00395"></a>00395     err_code = <a class="code" href="group__nrf__soc__api.html#gad1a939313c86ac881a0b1043715ef475" title="Set Interrupt Priority.">nrf_nvic_SetPriority</a>(GPIOTE_IRQn, NRF_APP_PRIORITY_LOW);
<a name="l00396"></a>00396     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00397"></a>00397     {
<a name="l00398"></a>00398         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00399"></a>00399     }
<a name="l00400"></a>00400 
<a name="l00401"></a>00401     err_code = <a class="code" href="group__nrf__soc__api.html#ga624ecb710ec5cdaf22893608d55c6f3a" title="Enable External Interrupt.">nrf_nvic_EnableIRQ</a>(GPIOTE_IRQn);
<a name="l00402"></a>00402     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00403"></a>00403     {
<a name="l00404"></a>00404         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00405"></a>00405     }
<a name="l00406"></a>00406 }
<a name="l00407"></a>00407 
<a name="l00408"></a>00408 
<a name="l00411"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga265c25c068555fbfae4ab4f391060040">00411</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>(<span class="keywordtype">void</span>)
<a name="l00412"></a>00412 {
<a name="l00413"></a>00413     <span class="comment">// Configure HR_INC_BUTTON_PIN_NO (Button 0) as a wake up button and also configure for &#39;pull</span>
<a name="l00414"></a>00414     <span class="comment">// up&#39; because the eval board does not have external pull up resistors connected to the buttons</span>
<a name="l00415"></a>00415     NRF_GPIO-&gt;PIN_CNF[<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga77ece330b6222b510f509e25282874b0">HR_INC_BUTTON_PIN_NO</a>] =
<a name="l00416"></a>00416                                           (GPIO_PIN_CNF_DIR_Input     &lt;&lt; GPIO_PIN_CNF_DIR_Pos)    |
<a name="l00417"></a>00417                                           (GPIO_PIN_CNF_INPUT_Connect &lt;&lt; GPIO_PIN_CNF_INPUT_Pos)  |
<a name="l00418"></a>00418                                           (GPIO_PIN_CNF_PULL_Pullup   &lt;&lt; GPIO_PIN_CNF_PULL_Pos)   |
<a name="l00419"></a>00419                                           (GPIO_PIN_CNF_DRIVE_S0S1    &lt;&lt; GPIO_PIN_CNF_DRIVE_Pos)  |
<a name="l00420"></a>00420                                           (GPIO_PIN_CNF_SENSE_Low     &lt;&lt; GPIO_PIN_CNF_SENSE_Pos);
<a name="l00421"></a>00421 
<a name="l00422"></a>00422     <span class="comment">// Configure HR_DEC_BUTTON_PIN_NO (Button 1) for &#39;pull up&#39; because the eval board does not have</span>
<a name="l00423"></a>00423     <span class="comment">// a external pull up resistors connected to the buttons</span>
<a name="l00424"></a>00424     NRF_GPIO-&gt;PIN_CNF[<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5713bbcd7b63f0a3fa11eb22f08417ff">HR_DEC_BUTTON_PIN_NO</a>] =
<a name="l00425"></a>00425                                           (GPIO_PIN_CNF_DIR_Input     &lt;&lt; GPIO_PIN_CNF_DIR_Pos)    |
<a name="l00426"></a>00426                                           (GPIO_PIN_CNF_INPUT_Connect &lt;&lt; GPIO_PIN_CNF_INPUT_Pos)  |
<a name="l00427"></a>00427                                           (GPIO_PIN_CNF_PULL_Pullup   &lt;&lt; GPIO_PIN_CNF_PULL_Pos)   |
<a name="l00428"></a>00428                                           (GPIO_PIN_CNF_DRIVE_S0S1    &lt;&lt; GPIO_PIN_CNF_DRIVE_Pos)  |
<a name="l00429"></a>00429                                           (GPIO_PIN_CNF_SENSE_Low     &lt;&lt; GPIO_PIN_CNF_SENSE_Pos);
<a name="l00430"></a>00430 }
<a name="l00431"></a>00431 
<a name="l00432"></a>00432 
<a name="l00437"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga09658aaa0774820d8f25249d551bc283">00437</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>(<span class="keywordtype">void</span>)
<a name="l00438"></a>00438 {
<a name="l00439"></a>00439     uint32_t err_code;
<a name="l00440"></a>00440     
<a name="l00441"></a>00441     <span class="comment">// Initialize timer module</span>
<a name="l00442"></a>00442     err_code = <a class="code" href="group__app__timer.html#ga4e1da5a2f64ee78ee97f7422ea97e439" title="Initializes the timer module.">app_timer_init</a>(NULL);
<a name="l00443"></a>00443     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00444"></a>00444     {
<a name="l00445"></a>00445         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00446"></a>00446     }
<a name="l00447"></a>00447 }
<a name="l00448"></a>00448 
<a name="l00449"></a>00449 
<a name="l00455"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga1004973353f351806e42896c491a5ab2">00455</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00456"></a>00456 {
<a name="l00457"></a>00457     uint32_t                err_code;
<a name="l00458"></a>00458     <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>   gap_conn_params;
<a name="l00459"></a>00459     <a class="code" href="structble__gap__conn__sec__mode__t.html" title="GAP link requirements.">ble_gap_conn_sec_mode_t</a> sec_mode;
<a name="l00460"></a>00460 
<a name="l00461"></a>00461     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;sec_mode);
<a name="l00462"></a>00462     
<a name="l00463"></a>00463     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga7d665aa56f8d248b8779a6cf170e2052" title="Set GAP device name.">ble_gap_device_name_set</a>(&amp;sec_mode, <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">DEVICE_NAME</a>);
<a name="l00464"></a>00464     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00465"></a>00465     {
<a name="l00466"></a>00466         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00467"></a>00467     }
<a name="l00468"></a>00468 
<a name="l00469"></a>00469     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga711f129fb97e0071ab04d2e994125f7a" title="Set GAP Appearance field.">ble_gap_appearance_set</a>(<a class="code" href="group___b_l_e___a_p_p_e_a_r_a_n_c_e_s.html#ga590996bfcab479b91c41ee10060e3ce7">BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT</a>);
<a name="l00470"></a>00470     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00471"></a>00471     {
<a name="l00472"></a>00472         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00473"></a>00473     }
<a name="l00474"></a>00474     
<a name="l00475"></a>00475     memset(&amp;gap_conn_params, 0, <span class="keyword">sizeof</span>(gap_conn_params));
<a name="l00476"></a>00476 
<a name="l00477"></a>00477     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga95196d5d0f40cf195a6001955d6d98cf">MIN_CONN_INTERVAL</a>;
<a name="l00478"></a>00478     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7d868ed8adb7d475b463fd8855907a18">MAX_CONN_INTERVAL</a>;
<a name="l00479"></a>00479     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a39219ac00a0e8ed843ee32b9df8be11e">slave_latency</a>     = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga0c921a874ac37870fc1516ce66cd228a">SLAVE_LATENCY</a>;
<a name="l00480"></a>00480     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a2089e7fb26f6b24882d1437eb5553bc7">conn_sup_timeout</a>  = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga799412c2b531ca347e13611e6e7523b9">CONN_SUP_TIMEOUT</a>;
<a name="l00481"></a>00481 
<a name="l00482"></a>00482     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;gap_conn_params);
<a name="l00483"></a>00483     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00484"></a>00484     {
<a name="l00485"></a>00485         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00486"></a>00486     }
<a name="l00487"></a>00487 }
<a name="l00488"></a>00488 
<a name="l00489"></a>00489 
<a name="l00495"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga935c9624de0709fe228dbefa4b54de48">00495</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>(<span class="keywordtype">void</span>)
<a name="l00496"></a>00496 {
<a name="l00497"></a>00497     uint32_t      err_code;
<a name="l00498"></a>00498     <a class="code" href="structble__advdata__t.html" title="Advertising data structure. This contains all options and data needed for encoding and setting the ad...">ble_advdata_t</a> advdata;
<a name="l00499"></a>00499     uint8_t       flags = <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga124514248a211b305eeac9cc370c7d77">BLE_GAP_DISC_MODE_GENERAL</a> | <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga346a5b47f4b8f94a08f320a0d8c14c18">BLE_GAP_DISC_BR_EDR_NOT_SUPPORTED</a>;
<a name="l00500"></a>00500     
<a name="l00501"></a>00501     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> adv_uuids[] = 
<a name="l00502"></a>00502     {
<a name="l00503"></a>00503         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gada8a8d4952d86f3557365ce0ead40e15">BLE_UUID_HEART_RATE_SERVICE</a>,         <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00504"></a>00504         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#ga4090520f3007fe6f90f06a6f4f8d5845">BLE_UUID_BATTERY_SERVICE</a>,            <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}, 
<a name="l00505"></a>00505         {<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#gab8eac87431b53cdfaeccd6d3a15ed5ac">BLE_UUID_DEVICE_INFORMATION_SERVICE</a>, <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}
<a name="l00506"></a>00506     };
<a name="l00507"></a>00507 
<a name="l00508"></a>00508     <span class="comment">// Build and set advertising data</span>
<a name="l00509"></a>00509     memset(&amp;advdata, 0, <span class="keyword">sizeof</span>(advdata));
<a name="l00510"></a>00510     
<a name="l00511"></a>00511     advdata.<a class="code" href="structble__advdata__t.html#a045ec5915c094e107ac24d185b83fa49">name_type</a>               = <a class="code" href="group__ble__sdk__lib__advdata.html#gga03c5ccf232779001be9786021b1a563ba63a26e22b9d6a0899edac755d0e2f488">BLE_ADVDATA_FULL_NAME</a>;
<a name="l00512"></a>00512     advdata.<a class="code" href="structble__advdata__t.html#aff2bb3e4016b9a7b6cbcdd6e98feb719">include_appearance</a>      = <span class="keyword">true</span>;
<a name="l00513"></a>00513     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#aaba88b24a21a6c70c895c0d55f4a69a0">size</a>              = <span class="keyword">sizeof</span>(flags);
<a name="l00514"></a>00514     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>            = &amp;flags;
<a name="l00515"></a>00515     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a1cecc52d144b939f33a67c1d68363e99">uuid_cnt</a> = <span class="keyword">sizeof</span>(adv_uuids) / <span class="keyword">sizeof</span>(adv_uuids[0]);
<a name="l00516"></a>00516     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a100265d2ed10e66a76e53cba205dc8a3">p_uuids</a>  = adv_uuids;
<a name="l00517"></a>00517     
<a name="l00518"></a>00518     err_code = <a class="code" href="group__ble__sdk__lib__advdata.html#ga180ff4057a0763688c734e98ab8d976b" title="Encodes and sets the advertising data and/or scan response data.">ble_advdata_set</a>(&amp;advdata, NULL);
<a name="l00519"></a>00519     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00520"></a>00520     {
<a name="l00521"></a>00521         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00522"></a>00522     }
<a name="l00523"></a>00523 
<a name="l00524"></a>00524     <span class="comment">// Initialise advertising parameters (used when starting advertising)</span>
<a name="l00525"></a>00525     memset(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>, 0, <span class="keyword">sizeof</span>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>));
<a name="l00526"></a>00526     
<a name="l00527"></a>00527     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a>        = <a class="code" href="group___b_l_e___g_a_p___a_d_v___t_y_p_e_s.html#ga6cc0db53453977ee0a31e59f07de2b86">BLE_GAP_ADV_TYPE_ADV_IND</a>;
<a name="l00528"></a>00528     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a27909d1b865548f236a871af2b6aa584">p_peer_addr</a> = NULL;                           <span class="comment">// Undirected advertisement</span>
<a name="l00529"></a>00529     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#aefdab55ee0f22565a03a14d09cc71d12">fp</a>          = <a class="code" href="group___b_l_e___g_a_p___a_d_v___f_i_l_t_e_r___p_o_l_i_c_i_e_s.html#ga0b0393df73db101d6cbfaede2dbb7ea6">BLE_GAP_ADV_FP_ANY</a>;
<a name="l00530"></a>00530     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a6c52a3d605c056768b59164ce8df8334">interval</a>    = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">APP_ADV_INTERVAL</a>;
<a name="l00531"></a>00531     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>.<a class="code" href="structble__gap__adv__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>     = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf58371bad8e1be8e2323df60379ed2df">APP_ADV_TIMEOUT_IN_SECONDS</a>;
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 
<a name="l00534"></a>00534 
<a name="l00539"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2">00539</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>(<span class="keywordtype">void</span>)
<a name="l00540"></a>00540 {
<a name="l00541"></a>00541     uint32_t       err_code;
<a name="l00542"></a>00542     <a class="code" href="structble__hrs__init__t.html" title="Heart Rate Service init structure. This contains all options and data needed for initialization of th...">ble_hrs_init_t</a> hrs_init;
<a name="l00543"></a>00543     <a class="code" href="structble__bas__init__t.html" title="Battery Service init structure. This contains all options and data needed for initialization of the s...">ble_bas_init_t</a> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga46507354f43dd16b32281f032e29d9c5" title="Initialize Battery Service.">bas_init</a>;
<a name="l00544"></a>00544     <a class="code" href="structble__dis__init__t.html" title="Device Information Service init structure. This contains all possible characteristics needed for init...">ble_dis_init_t</a> <a class="code" href="group__ble__sdk__app__hids__keyboard__main.html#ga2d0743f12929b17b64c5c2fb101a9350" title="Initialize Device Information Service.">dis_init</a>;
<a name="l00545"></a>00545     uint8_t        body_sensor_location;
<a name="l00546"></a>00546     
<a name="l00547"></a>00547     <span class="comment">// Initialize Heart Rate Service</span>
<a name="l00548"></a>00548     body_sensor_location = BLE_HRS_BODY_SENSOR_LOCATION_FINGER;
<a name="l00549"></a>00549     
<a name="l00550"></a>00550     memset(&amp;hrs_init, 0, <span class="keyword">sizeof</span>(hrs_init));
<a name="l00551"></a>00551     
<a name="l00552"></a>00552     hrs_init.<a class="code" href="structble__hrs__init__t.html#a72fb2dea328affc259a55ca2447d0a48">is_sensor_contact_supported</a> = <span class="keyword">false</span>;
<a name="l00553"></a>00553     hrs_init.<a class="code" href="structble__hrs__init__t.html#a89a0f7e39b46019e49fb392689f6073c">p_body_sensor_location</a>      = &amp;body_sensor_location;
<a name="l00554"></a>00554 
<a name="l00555"></a>00555     <span class="comment">// Here the sec level for the Heart Rate Service can be changed/increased.</span>
<a name="l00556"></a>00556     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.cccd_write_perm);
<a name="l00557"></a>00557     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00558"></a>00558     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a670a4c608f847ac03bd66005b30068c3">hrs_hrm_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00559"></a>00559 
<a name="l00560"></a>00560     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00561"></a>00561     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;hrs_init.<a class="code" href="structble__hrs__init__t.html#a2b688c05a8f04acd31acf2c55c3efc84">hrs_bsl_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00562"></a>00562 
<a name="l00563"></a>00563     err_code = <a class="code" href="group__ble__sdk__srv__hrs.html#ga94256c7eb29129ff352ca53adf1ad5b8" title="Initialize the Heart Rate Service.">ble_hrs_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, &amp;hrs_init);
<a name="l00564"></a>00564     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00565"></a>00565     {
<a name="l00566"></a>00566         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00567"></a>00567     }
<a name="l00568"></a>00568     
<a name="l00569"></a>00569     <span class="comment">// Initialize Battery Service</span>
<a name="l00570"></a>00570     memset(&amp;bas_init, 0, <span class="keyword">sizeof</span>(bas_init));
<a name="l00571"></a>00571     
<a name="l00572"></a>00572     <span class="comment">// Here the sec level for the Battery Service can be changed/increased.</span>
<a name="l00573"></a>00573     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.cccd_write_perm);
<a name="l00574"></a>00574     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00575"></a>00575     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#ada6a205c81f51d9aa2de33bbdea0bd26">battery_level_char_attr_md</a>.<a class="code" href="structble__srv__cccd__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00576"></a>00576 
<a name="l00577"></a>00577     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;bas_init.<a class="code" href="structble__bas__init__t.html#a2c9724572f64316880f915bb78882de0">battery_level_report_read_perm</a>);
<a name="l00578"></a>00578 
<a name="l00579"></a>00579     bas_init.<a class="code" href="structble__bas__init__t.html#a3c25f96941dd8c1b92407ed2994691c6">evt_handler</a>          = NULL;
<a name="l00580"></a>00580     bas_init.<a class="code" href="structble__bas__init__t.html#adbf298550acd37c0d6170e90504318ac">support_notification</a> = <span class="keyword">true</span>;
<a name="l00581"></a>00581     bas_init.<a class="code" href="structble__bas__init__t.html#ac3ce984f1c066cfc0911e98fa1acdc8e">p_report_ref</a>         = NULL;
<a name="l00582"></a>00582     bas_init.<a class="code" href="structble__bas__init__t.html#ae5e656df4b847b3a099792ae32676d16">initial_batt_level</a>   = 100;
<a name="l00583"></a>00583     
<a name="l00584"></a>00584     err_code = <a class="code" href="group__ble__sdk__srv__bas.html#gacb8ac9205dcec39e216575c76261c807" title="Initialize the Battery Service.">ble_bas_init</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, &amp;bas_init);
<a name="l00585"></a>00585     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00586"></a>00586     {
<a name="l00587"></a>00587         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00588"></a>00588     }
<a name="l00589"></a>00589 
<a name="l00590"></a>00590     <span class="comment">// Initialize Device Information Service</span>
<a name="l00591"></a>00591     memset(&amp;dis_init, 0, <span class="keyword">sizeof</span>(dis_init));
<a name="l00592"></a>00592     
<a name="l00593"></a>00593     <a class="code" href="group__ble__sdk__srv__common.html#ga611dfcf7209a57c2e45964e8bb4c5756" title="Make UTF-8 structure refer to an ASCII string.">ble_srv_ascii_to_utf8</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#a02a650cde3f65fc67f65b5fb4cd33425">manufact_name_str</a>, <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaaa2b8f5b105c3019df0cb346f472e803">MANUFACTURER_NAME</a>);
<a name="l00594"></a>00594 
<a name="l00595"></a>00595     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#af0352a482ca2a1305ec5941bc4af0ec2">read_perm</a>);
<a name="l00596"></a>00596     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga1cf3822f8bb11e28931afbb9179665b7" title="Set sec_mode pointed to by ptr to have no access rights.">BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS</a>(&amp;dis_init.<a class="code" href="structble__dis__init__t.html#aa3268ab4659686cb4202651e071af265">dis_attr_md</a>.<a class="code" href="structble__srv__security__mode__t.html#a6060006e42afe1970aed0a8490f71445">write_perm</a>);
<a name="l00597"></a>00597 
<a name="l00598"></a>00598     err_code = <a class="code" href="group__ble__sdk__srv__dis.html#ga472c83dfe2ad977d76b664095a4991cd" title="Initialize the Device Information Service.">ble_dis_init</a>(&amp;dis_init);
<a name="l00599"></a>00599     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00600"></a>00600     {
<a name="l00601"></a>00601         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00602"></a>00602     }
<a name="l00603"></a>00603 }
<a name="l00604"></a>00604 
<a name="l00605"></a>00605 
<a name="l00608"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga9f11118fb9ce22ad1afe20af6f89b131">00608</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00609"></a>00609 {
<a name="l00610"></a>00610     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>      = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7c1fffb0f865552108560d4c63b32db1">SEC_PARAM_TIMEOUT</a>;
<a name="l00611"></a>00611     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a3d9eee3a6a1d710b0e5d13b567675694">bond</a>         = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacbf03a82593c273743a5a80a1119b851">SEC_PARAM_BOND</a>;
<a name="l00612"></a>00612     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a808e5ec85cf1656a05a985386ba29276">mitm</a>         = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab6831ebe113f8afe970326b7742b5947">SEC_PARAM_MITM</a>;
<a name="l00613"></a>00613     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a81d248b843331e8798478feecf4f4c92">io_caps</a>      = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga42df85b3a4083cdc614d9111d580d98f">SEC_PARAM_IO_CAPABILITIES</a>;
<a name="l00614"></a>00614     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a01318f39f3b3471bd44bf2f322331788">oob</a>          = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">SEC_PARAM_OOB</a>;  
<a name="l00615"></a>00615     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a66c3e526aae4ca7f3212ae207225b0a2">min_key_size</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">SEC_PARAM_MIN_KEY_SIZE</a>;
<a name="l00616"></a>00616     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a43d814618fbf7f63a318966dd84746c2">max_key_size</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf2cd1595de153ea1d6d843619a1a7707">SEC_PARAM_MAX_KEY_SIZE</a>;
<a name="l00617"></a>00617 }
<a name="l00618"></a>00618 
<a name="l00621"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga59f2752bdf059ab72ec3987d0b1db770">00621</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga59f2752bdf059ab72ec3987d0b1db770" title="Start application timers.">application_timers_start</a>(<span class="keywordtype">void</span>)
<a name="l00622"></a>00622 {
<a name="l00623"></a>00623     uint32_t err_code;
<a name="l00624"></a>00624     
<a name="l00625"></a>00625     <span class="comment">// Start application timers</span>
<a name="l00626"></a>00626     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_BATTERY_LEVEL_MEAS, 
<a name="l00627"></a>00627                                <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7e5b3d2cf024dde83b8c536b22a1c155" title="Battery measurement timer timeout handler.">battery_level_meas_timeout_handler</a>, 
<a name="l00628"></a>00628                                <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf28f0232a3fdc0eb03b94eb34b25cde8">BATTERY_LEVEL_MEAS_INTERVAL</a>, 
<a name="l00629"></a>00629                                APP_TIMER_MODE_REPEATED, 
<a name="l00630"></a>00630                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00631"></a>00631     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00632"></a>00632     {
<a name="l00633"></a>00633         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00634"></a>00634     }
<a name="l00635"></a>00635     
<a name="l00636"></a>00636     err_code = <a class="code" href="group__app__timer.html#ga54651d3dc5266bd7541b80918527b060" title="Starts a timer.">app_timer_start</a>(APP_TIMER_HEART_RATE_MEAS, 
<a name="l00637"></a>00637                                <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5f2bc03dde9dbfbd8983fdf45085d55b" title="Heart rate measurement timer timeout handler.">heart_rate_meas_timeout_handler</a>, 
<a name="l00638"></a>00638                                <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga45a3c3dc5dec56bf2ed3d1c4fdb0ccdd">HEART_RATE_MEAS_INTERVAL</a>, 
<a name="l00639"></a>00639                                APP_TIMER_MODE_REPEATED, 
<a name="l00640"></a>00640                                <a class="code" href="group__app__timer.html#ga02ba0b12340bf53b472283b752257f06">APP_TIMER_LOWEST_PRI</a>);
<a name="l00641"></a>00641     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00642"></a>00642     {
<a name="l00643"></a>00643         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00644"></a>00644     }
<a name="l00645"></a>00645 }
<a name="l00646"></a>00646 
<a name="l00647"></a>00647 
<a name="l00653"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa6e09b0d303b4659d4601bdcf07870dc">00653</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa6e09b0d303b4659d4601bdcf07870dc" title="Function to start flashing the LED.">led_start_flashing</a>(<span class="keywordtype">void</span>)
<a name="l00654"></a>00654 {
<a name="l00655"></a>00655     <span class="comment">// Configure the GPIOTE Task to toggle the LED state.</span>
<a name="l00656"></a>00656     <a class="code" href="group__nrf__gpiote.html#gab8667667ddf3bdca874df3add96fb622" title="Config GPIOTE channel as output, setting the properly desired output level.">nrf_gpiote_task_config</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga79bf7625596d78764844d19ef2a59021">GPIOTE_CHAN_FOR_LED_TASK</a>,
<a name="l00657"></a>00657                            ADVERTISING_LED_PIN_NO,
<a name="l00658"></a>00658                            <a class="code" href="group__nrf__gpiote.html#gga9a424db0997c11092f8f69d52155dd9da00487cd8286ff071ca751cd4a00295d5" title="Toggle.">NRF_GPIOTE_POLARITY_TOGGLE</a>,
<a name="l00659"></a>00659                            <a class="code" href="group__nrf__gpiote.html#ggab280bbb7269ab98a97e7b47d906ef9aaae0df1a0e930bfe3b198a9692d9916667" title="Low to high.">NRF_GPIOTE_INITIAL_VALUE_LOW</a>);
<a name="l00660"></a>00660 
<a name="l00661"></a>00661     NRF_TIMER1-&gt;TASKS_START = 1;
<a name="l00662"></a>00662 }
<a name="l00663"></a>00663 
<a name="l00664"></a>00664 
<a name="l00670"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacc7af227286add18ee1b0d186cad60fb">00670</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacc7af227286add18ee1b0d186cad60fb" title="Function to stop flashing the LED.">led_stop_flashing</a>(<span class="keywordtype">void</span>)
<a name="l00671"></a>00671 {
<a name="l00672"></a>00672     <span class="comment">// Disable the GPIOTE_CHAN_FOR_LED_TASK. This is because when an task has been configured</span>
<a name="l00673"></a>00673     <span class="comment">// to operate on a pin, the pin can only be written from GPIOTE module. Attempting to write a</span>
<a name="l00674"></a>00674     <span class="comment">// pin (using nrf_gpio_pin_clear() below for example) as a normal GPIO pin will have no effect.</span>
<a name="l00675"></a>00675     NRF_GPIOTE-&gt;CONFIG[<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga79bf7625596d78764844d19ef2a59021">GPIOTE_CHAN_FOR_LED_TASK</a>] =
<a name="l00676"></a>00676                                             (GPIOTE_CONFIG_MODE_Disabled &lt;&lt; GPIOTE_CONFIG_MODE_Pos);
<a name="l00677"></a>00677 
<a name="l00678"></a>00678     NRF_TIMER1-&gt;TASKS_STOP = 1;
<a name="l00679"></a>00679 
<a name="l00680"></a>00680     <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00681"></a>00681 }
<a name="l00682"></a>00682 
<a name="l00683"></a>00683 
<a name="l00686"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadf80cd84ee702e57a2a416fe4f653eb8">00686</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>(<span class="keywordtype">void</span>)
<a name="l00687"></a>00687 {
<a name="l00688"></a>00688     uint32_t err_code;
<a name="l00689"></a>00689 
<a name="l00690"></a>00690     err_code = <a class="code" href="group___b_l_e___g_a_p.html#gabdbf78c3a8b09c6f2fb92d8733096af8" title="Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_start</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga50483ecf69a0ae87ce1a8a5e8fa73c04">s_adv_params</a>);
<a name="l00691"></a>00691     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00692"></a>00692     {
<a name="l00693"></a>00693         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00694"></a>00694     }
<a name="l00695"></a>00695         
<a name="l00696"></a>00696     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa6e09b0d303b4659d4601bdcf07870dc" title="Function to start flashing the LED.">led_start_flashing</a>();
<a name="l00697"></a>00697 }
<a name="l00698"></a>00698 
<a name="l00699"></a>00699 
<a name="l00704"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa">00704</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>(uint32_t nrf_error)
<a name="l00705"></a>00705 {
<a name="l00706"></a>00706     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00707"></a>00707 }
<a name="l00708"></a>00708 
<a name="l00709"></a>00709 
<a name="l00712"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf61b6c1c47f5c96b169ff81c345d7849">00712</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00713"></a>00713 {
<a name="l00714"></a>00714     uint32_t               err_code;
<a name="l00715"></a>00715     <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> cp_init;
<a name="l00716"></a>00716     
<a name="l00717"></a>00717     memset(&amp;cp_init, 0, <span class="keyword">sizeof</span>(cp_init));
<a name="l00718"></a>00718 
<a name="l00719"></a>00719     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>                  = NULL;
<a name="l00720"></a>00720     cp_init.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">FIRST_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00721"></a>00721     cp_init.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>  = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadf85796ef07632ed27e0bce9509d9245">NEXT_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00722"></a>00722     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>   = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">MAX_CONN_PARAMS_UPDATE_COUNT</a>;
<a name="l00723"></a>00723     cp_init.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>    = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>.<a class="code" href="structble__hrs__s.html#af683c5e3e8c692ba6c20d8941483ce50">hrm_handles</a>.<a class="code" href="structble__gatts__char__handles__t.html#a2c7796d4eb58c25a1a724bcd9d5bf183">cccd_handle</a>;
<a name="l00724"></a>00724     cp_init.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>             = <span class="keyword">true</span>;
<a name="l00725"></a>00725     cp_init.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>                    = NULL;
<a name="l00726"></a>00726     cp_init.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>;
<a name="l00727"></a>00727     
<a name="l00728"></a>00728     err_code = <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(&amp;cp_init);
<a name="l00729"></a>00729     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00730"></a>00730     {
<a name="l00731"></a>00731         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00732"></a>00732     }
<a name="l00733"></a>00733 }
<a name="l00734"></a>00734 
<a name="l00735"></a>00735 
<a name="l00738"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaff016ad71b5161ca8ad06bf590d973d4">00738</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaff016ad71b5161ca8ad06bf590d973d4" title="Function to put the chip in System OFF Mode.">system_off_mode_enter</a>(<span class="keywordtype">void</span>)
<a name="l00739"></a>00739 {
<a name="l00740"></a>00740     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga302701614c7bb1c9fc01dafec2bb04fb" title="Puts the chip in System OFF mode.">nrf_power_system_off</a>();
<a name="l00741"></a>00741     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00742"></a>00742     {
<a name="l00743"></a>00743         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00744"></a>00744     }
<a name="l00745"></a>00745 }
<a name="l00746"></a>00746 
<a name="l00747"></a>00747 
<a name="l00752"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9">00752</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00753"></a>00753 {
<a name="l00754"></a>00754     uint32_t                         err_code = <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00755"></a>00755     <span class="keyword">static</span> uint16_t                  <a class="code" href="group__ble__sdk__app__hrs__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00756"></a>00756     <span class="keyword">static</span> <a class="code" href="structble__gap__evt__auth__status__t.html" title="Event data for authentication status event.">ble_gap_evt_auth_status_t</a> s_auth_status;
<a name="l00757"></a>00757     <a class="code" href="structble__gap__enc__info__t.html" title="GAP Encryption Information.">ble_gap_enc_info_t</a> *             p_enc_info;
<a name="l00758"></a>00758     
<a name="l00759"></a>00759     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00760"></a>00760     {
<a name="l00761"></a>00761         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00762"></a>00762             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacc7af227286add18ee1b0d186cad60fb" title="Function to stop flashing the LED.">led_stop_flashing</a>();
<a name="l00763"></a>00763 
<a name="l00764"></a>00764             s_conn_handle = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00765"></a>00765 
<a name="l00766"></a>00766             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga59f2752bdf059ab72ec3987d0b1db770" title="Start application timers.">application_timers_start</a>(); <span class="comment">// Start timers used to generate battery and HR measurements.</span>
<a name="l00767"></a>00767 
<a name="l00768"></a>00768             <span class="comment">// Initialize the current heart rate to the average of max and min values. So that </span>
<a name="l00769"></a>00769             <span class="comment">// everytime a new connection is made, the heart rate starts from the same value.</span>
<a name="l00770"></a>00770             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> = (<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5c6a36078512a923ab07d1b8276c8cca">MAX_HEART_RATE</a> + <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">MIN_HEART_RATE</a>) / 2;
<a name="l00771"></a>00771             <span class="keywordflow">break</span>;
<a name="l00772"></a>00772             
<a name="l00773"></a>00773         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00774"></a>00774             <span class="comment">// Go to system-off mode, should not return from this function, wakeup will trigger</span>
<a name="l00775"></a>00775             <span class="comment">// a reset.</span>
<a name="l00776"></a>00776             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaff016ad71b5161ca8ad06bf590d973d4" title="Function to put the chip in System OFF Mode.">system_off_mode_enter</a>();
<a name="l00777"></a>00777             <span class="keywordflow">break</span>;
<a name="l00778"></a>00778 
<a name="l00779"></a>00779         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da6c5eefbcfabbc1ce4a8bcbf550c285ae">BLE_GAP_EVT_SEC_PARAMS_REQUEST</a>:
<a name="l00780"></a>00780             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga5339c2562371354a0e3752b86214b92a" title="Reply with GAP security parameters.">ble_gap_sec_params_reply</a>(s_conn_handle, 
<a name="l00781"></a>00781                                                 <a class="code" href="group___b_l_e___g_a_p___s_e_c___s_t_a_t_u_s.html#gaa0334dea24e449e5c28c88bbe8a1d00f">BLE_GAP_SEC_STATUS_SUCCESS</a>, 
<a name="l00782"></a>00782                                                 &amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00783"></a>00783             <span class="keywordflow">break</span>;
<a name="l00784"></a>00784             
<a name="l00785"></a>00785         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da8958220152f7547da3b250b4f724877c">BLE_GAP_EVT_AUTH_STATUS</a>:
<a name="l00786"></a>00786             s_auth_status = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a350f0c3a127499fb3d522d361554e3eb">auth_status</a>;
<a name="l00787"></a>00787             <span class="keywordflow">break</span>;
<a name="l00788"></a>00788 
<a name="l00789"></a>00789         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaae3776204f11a583e105aed0e477601da">BLE_GATTS_EVT_SYS_ATTR_MISSING</a>:
<a name="l00790"></a>00790             err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga65ae169e49530eb2fa4bf73053060a13" title="Update persistent system attribute info.">ble_gatts_sys_attr_set</a>(s_conn_handle, NULL, 0);
<a name="l00791"></a>00791             <span class="keywordflow">break</span>;
<a name="l00792"></a>00792 
<a name="l00793"></a>00793         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daf1c60079f92820cb933ebdb66d2d8d7d">BLE_GAP_EVT_SEC_INFO_REQUEST</a>:
<a name="l00794"></a>00794             p_enc_info = &amp;s_auth_status.periph_keys.<a class="code" href="structble__gap__evt__auth__status__t_1_1periph__keys__t.html#a7eee7ec3b96cc86a0080ab368dae817d">enc_info</a>;
<a name="l00795"></a>00795             <span class="keywordflow">if</span> (p_enc_info-&gt;<a class="code" href="structble__gap__enc__info__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a> == p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a5f04f763d053c94297246b6ed351c66a">sec_info_request</a>.<a class="code" href="structble__gap__evt__sec__info__request__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a>)
<a name="l00796"></a>00796             {
<a name="l00797"></a>00797                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(s_conn_handle, p_enc_info, NULL);
<a name="l00798"></a>00798             }
<a name="l00799"></a>00799             <span class="keywordflow">else</span>
<a name="l00800"></a>00800             {
<a name="l00801"></a>00801                 <span class="comment">// No keys found for this device</span>
<a name="l00802"></a>00802                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(s_conn_handle, NULL, NULL);
<a name="l00803"></a>00803             }
<a name="l00804"></a>00804             <span class="keywordflow">break</span>;
<a name="l00805"></a>00805 
<a name="l00806"></a>00806         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da57e5d1061d9b3d1500fb3556a3fb8847">BLE_GAP_EVT_TIMEOUT</a>:
<a name="l00807"></a>00807             <span class="keywordflow">if</span> (p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a17e289da592e731cde1451c2d5f3f24a">timeout</a>.<a class="code" href="structble__gap__evt__timeout__t.html#af5eca485cd2b34522478907d4c8f5bc6">src</a> == <a class="code" href="group___b_l_e___g_a_p___t_i_m_e_o_u_t___t_y_p_e_s.html#gafee7b7095fb21ed922c6719cc1c2d23f">BLE_GAP_TIMEOUT_TYPE_ADVERTISEMENT</a>)
<a name="l00808"></a>00808             { 
<a name="l00809"></a>00809                 <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacc7af227286add18ee1b0d186cad60fb" title="Function to stop flashing the LED.">led_stop_flashing</a>();
<a name="l00810"></a>00810                 
<a name="l00811"></a>00811                 <span class="comment">// Go to system-off mode (this function will not return; wakeup will cause a reset)</span>
<a name="l00812"></a>00812                 <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaff016ad71b5161ca8ad06bf590d973d4" title="Function to put the chip in System OFF Mode.">system_off_mode_enter</a>();
<a name="l00813"></a>00813             }
<a name="l00814"></a>00814             <span class="keywordflow">break</span>;
<a name="l00815"></a>00815             
<a name="l00816"></a>00816         <span class="keywordflow">default</span>:
<a name="l00817"></a>00817             <span class="keywordflow">break</span>;
<a name="l00818"></a>00818     }
<a name="l00819"></a>00819     
<a name="l00820"></a>00820     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00821"></a>00821     {
<a name="l00822"></a>00822         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00823"></a>00823     }
<a name="l00824"></a>00824 }
<a name="l00825"></a>00825 
<a name="l00826"></a>00826 
<a name="l00847"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga893d9dbed647c5c5d9b6b1925b15ada4">00847</a> <span class="keyword">static</span> uint8_t <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga893d9dbed647c5c5d9b6b1925b15ada4" title="Converts the input voltage (in milli volts) into percentage of 3.0 Volts.">battery_level_in_percent</a>(<span class="keyword">const</span> uint16_t mvolts)
<a name="l00848"></a>00848 {
<a name="l00849"></a>00849     uint8_t battery_level;
<a name="l00850"></a>00850 
<a name="l00851"></a>00851     <span class="keywordflow">if</span> (mvolts &gt;= 3000)
<a name="l00852"></a>00852     {
<a name="l00853"></a>00853         battery_level = 100;
<a name="l00854"></a>00854     }
<a name="l00855"></a>00855     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mvolts &gt; 2900)
<a name="l00856"></a>00856     {
<a name="l00857"></a>00857         battery_level = 100 - ((3000 - mvolts) * 58) / 100;
<a name="l00858"></a>00858     }
<a name="l00859"></a>00859     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mvolts &gt; 2740)
<a name="l00860"></a>00860     {
<a name="l00861"></a>00861         battery_level = 42 - ((2900 - mvolts) * 24) / 160;
<a name="l00862"></a>00862     }
<a name="l00863"></a>00863     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mvolts &gt; 2440)
<a name="l00864"></a>00864     {
<a name="l00865"></a>00865         battery_level = 18 - ((2740 - mvolts) * 12) / 300;
<a name="l00866"></a>00866     }
<a name="l00867"></a>00867     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (mvolts &gt; 2100)
<a name="l00868"></a>00868     {
<a name="l00869"></a>00869         battery_level = 6 - ((2440 - mvolts) * 6) / 340;
<a name="l00870"></a>00870     }
<a name="l00871"></a>00871     <span class="keywordflow">else</span>
<a name="l00872"></a>00872     {
<a name="l00873"></a>00873         battery_level = 0;
<a name="l00874"></a>00874     }
<a name="l00875"></a>00875 
<a name="l00876"></a>00876     <span class="keywordflow">return</span> battery_level;
<a name="l00877"></a>00877 }
<a name="l00878"></a>00878 
<a name="l00879"></a>00879 
<a name="l00884"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga06406eadf297fa89a6eaf9586b227a69">00884</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga06406eadf297fa89a6eaf9586b227a69" title="ADC interrupt handler.">ADC_IRQHandler</a>(<span class="keywordtype">void</span>)
<a name="l00885"></a>00885 {
<a name="l00886"></a>00886     <span class="keywordflow">if</span> (NRF_ADC-&gt;EVENTS_END != 0)
<a name="l00887"></a>00887     {
<a name="l00888"></a>00888         uint8_t     adc_result;
<a name="l00889"></a>00889         uint16_t    batt_lvl_in_milli_volts;
<a name="l00890"></a>00890         uint8_t     percentage_batt_lvl;
<a name="l00891"></a>00891 
<a name="l00892"></a>00892         NRF_ADC-&gt;EVENTS_END     = 0;
<a name="l00893"></a>00893         adc_result              = NRF_ADC-&gt;RESULT;
<a name="l00894"></a>00894         batt_lvl_in_milli_volts = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga0552bb76e072f5519938dfdb8b9b8b03" title="Macro to convert the result of ADC conversion in millivolts.">ADC_RESULT_IN_MILLI_VOLTS</a>(adc_result) +
<a name="l00895"></a>00895                                   <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga66573611a61405487b66c513f0662c45">DIODE_FWD_VOLT_DROP_MILLIVOLTS</a>;
<a name="l00896"></a>00896         percentage_batt_lvl     = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga893d9dbed647c5c5d9b6b1925b15ada4" title="Converts the input voltage (in milli volts) into percentage of 3.0 Volts.">battery_level_in_percent</a>(batt_lvl_in_milli_volts);
<a name="l00897"></a>00897 
<a name="l00898"></a>00898         <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga57efeb20271786f1b6db8bdb4b1d0ee4" title="Update the given Battery Level characteristic in Battery Service.">battery_level_update</a>(percentage_batt_lvl);
<a name="l00899"></a>00899     }
<a name="l00900"></a>00900 }
<a name="l00901"></a>00901 
<a name="l00902"></a>00902 
<a name="l00910"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e">00910</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00911"></a>00911 {
<a name="l00912"></a>00912     <a class="code" href="group__ble__sdk__srv__hrs.html#gac50e029608199cc8d52463acb3e8a02e" title="Heart Rate Service BLE stack event handler.">ble_hrs_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3e49fa0f1c47f72e98bc05de96dd24d4">s_hrs</a>, p_ble_evt);
<a name="l00913"></a>00913     <a class="code" href="group__ble__sdk__srv__bas.html#ga01b70d77540660d7e312121d9f1d3b3a" title="Battery Service BLE stack event handler.">ble_bas_on_ble_evt</a>(&amp;<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab22f840926bbada5a0ba32f2f7dc94b3">s_bas</a>, p_ble_evt);
<a name="l00914"></a>00914     <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(p_ble_evt);
<a name="l00915"></a>00915     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(p_ble_evt);
<a name="l00916"></a>00916 }
<a name="l00917"></a>00917 
<a name="l00918"></a>00918 
<a name="l00924"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a">00924</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(<span class="keywordtype">void</span>)
<a name="l00925"></a>00925 {
<a name="l00926"></a>00926     uint32_t err_code = <a class="code" href="group__ble__stack__handler.html#gada9282a45a226bbe8544995b2fbf22dd" title="Initialize stack handler module.">ble_stack_handler_init</a>(<a class="code" href="group__nrf__sdm__api.html#ggaaf8fd5f0e57d456151c951e0f3715fc4a1c5e9917211a50eac336a3fd2e467756">NRF_CLOCK_LFCLKSRC_XTAL_20_PPM</a>, <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga2b08d6ccb6e7f4588d2ac843d4494c0e" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>);
<a name="l00927"></a>00927     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00928"></a>00928     {
<a name="l00929"></a>00929         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00930"></a>00930     }
<a name="l00931"></a>00931 }
<a name="l00932"></a>00932 
<a name="l00933"></a>00933 
<a name="l00936"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga26b108e2296d5514a2391960b4231d71">00936</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga26b108e2296d5514a2391960b4231d71" title="GPIOTE interrupt handler.">GPIOTE_IRQHandler</a>(<span class="keywordtype">void</span>)
<a name="l00937"></a>00937 {
<a name="l00938"></a>00938     <span class="keywordflow">if</span> (
<a name="l00939"></a>00939         (NRF_GPIOTE-&gt;EVENTS_PORT != 0)
<a name="l00940"></a>00940         &amp;&amp;
<a name="l00941"></a>00941         ((NRF_GPIOTE-&gt;INTENSET &amp; GPIOTE_INTENSET_PORT_Msk) != 0)
<a name="l00942"></a>00942     )
<a name="l00943"></a>00943     {
<a name="l00944"></a>00944         NRF_GPIOTE-&gt;EVENTS_PORT = 0;
<a name="l00945"></a>00945 
<a name="l00946"></a>00946         <span class="comment">// Handle button for incrementing heart rate</span>
<a name="l00947"></a>00947         <span class="keywordflow">if</span> (<a class="code" href="group__nrf__gpio.html#ga0983906029818d8aa199b71b578d1c12" title="Read the input level of a GPIO pin.">nrf_gpio_pin_read</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga77ece330b6222b510f509e25282874b0">HR_INC_BUTTON_PIN_NO</a>) == 0)
<a name="l00948"></a>00948         {
<a name="l00949"></a>00949             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> += <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab604f2d2e09476706dece4ba10d23083">HEART_RATE_CHANGE</a>;
<a name="l00950"></a>00950             <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> &gt; <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5c6a36078512a923ab07d1b8276c8cca">MAX_HEART_RATE</a>)
<a name="l00951"></a>00951             {
<a name="l00952"></a>00952                 <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">MIN_HEART_RATE</a>; <span class="comment">// Loop back</span>
<a name="l00953"></a>00953             }
<a name="l00954"></a>00954         }
<a name="l00955"></a>00955         
<a name="l00956"></a>00956         <span class="comment">// Handle button for decrementing heart rate</span>
<a name="l00957"></a>00957         <span class="keywordflow">if</span> (<a class="code" href="group__nrf__gpio.html#ga0983906029818d8aa199b71b578d1c12" title="Read the input level of a GPIO pin.">nrf_gpio_pin_read</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5713bbcd7b63f0a3fa11eb22f08417ff">HR_DEC_BUTTON_PIN_NO</a>) == 0)
<a name="l00958"></a>00958         {
<a name="l00959"></a>00959             <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> -= <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gab604f2d2e09476706dece4ba10d23083">HEART_RATE_CHANGE</a>;
<a name="l00960"></a>00960             <span class="keywordflow">if</span> (<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> &lt; <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga8806d3ee13116211450e6fb3a2fb68a4">MIN_HEART_RATE</a>)
<a name="l00961"></a>00961             {
<a name="l00962"></a>00962                 <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadae58610d8b39e6c4bf07c8dc7ae8a92">s_cur_heart_rate</a> = <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5c6a36078512a923ab07d1b8276c8cca">MAX_HEART_RATE</a>; <span class="comment">// Loop back</span>
<a name="l00963"></a>00963             }
<a name="l00964"></a>00964         }
<a name="l00965"></a>00965     }
<a name="l00966"></a>00966 }
<a name="l00967"></a>00967 
<a name="l00968"></a>00968 
<a name="l00974"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga97fa4e65e4113a20dffefb8c9ffd1d08">00974</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga97fa4e65e4113a20dffefb8c9ffd1d08" title="PINs initialisation.">pins_init</a>(<span class="keywordtype">void</span>)
<a name="l00975"></a>00975 {
<a name="l00976"></a>00976     uint8_t i;
<a name="l00977"></a>00977     
<a name="l00978"></a>00978     NRF_GPIO-&gt;DIRCLR = 0xFFFFFFFF;
<a name="l00979"></a>00979     
<a name="l00980"></a>00980     <span class="keywordflow">for</span> (i = 0; i &lt; <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga86b4a9059f88ccc1bc39a767ab2d1dc3">TOTAL_NUMBER_OF_IO_PINS</a>; i++)
<a name="l00981"></a>00981     {
<a name="l00982"></a>00982         NRF_GPIO-&gt;PIN_CNF[i] = GPIO_PIN_CNF_INPUT_Msk;
<a name="l00983"></a>00983     }
<a name="l00984"></a>00984 }
<a name="l00985"></a>00985 
<a name="l00986"></a>00986 
<a name="l00989"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3adda2642702fdb99b08992c39494000">00989</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>(<span class="keywordtype">void</span>)
<a name="l00990"></a>00990 {
<a name="l00991"></a>00991     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga2aae5f388f1b6179058c62e2fb05a547" title="Waits for an application event.">nrf_wait_for_app_event</a>();
<a name="l00992"></a>00992     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00993"></a>00993     {
<a name="l00994"></a>00994         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00995"></a>00995     }
<a name="l00996"></a>00996 }
<a name="l00997"></a>00997 
<a name="l00998"></a>00998 
<a name="l01003"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacb0906fa1cb3aeed8e86dfdb6abdd5fd">01003</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacb0906fa1cb3aeed8e86dfdb6abdd5fd" title="Function to initalise the peripherals needed for generating PWM input to flash an LED...">pwm_config_init</a>(<span class="keywordtype">void</span>)
<a name="l01004"></a>01004 {
<a name="l01005"></a>01005     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gad22626704ea5d45f863163500e355cc3" title="Initialize GPIOTE module.">gpiote_init</a>();
<a name="l01006"></a>01006     ppi_init();
<a name="l01007"></a>01007     timer1_init();
<a name="l01008"></a>01008 }
<a name="l01009"></a>01009 
<a name="l01010"></a>01010 
<a name="l01013"></a><a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga840291bc02cba5474a4cb46a9b9566fe">01013</a> <span class="keywordtype">int</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#ga840291bc02cba5474a4cb46a9b9566fe" title="Application main function.">main</a>(<span class="keywordtype">void</span>)
<a name="l01014"></a>01014 {
<a name="l01015"></a>01015     <span class="keywordtype">bool</span> is_startup_on_button_press = <span class="keyword">true</span>;
<a name="l01016"></a>01016 
<a name="l01017"></a>01017     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga97fa4e65e4113a20dffefb8c9ffd1d08" title="PINs initialisation.">pins_init</a>();
<a name="l01018"></a>01018     <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>();
<a name="l01019"></a>01019 
<a name="l01020"></a>01020     <span class="comment">// Check button states.</span>
<a name="l01021"></a>01021     <span class="keywordflow">if</span> (
<a name="l01022"></a>01022         (<a class="code" href="group__nrf__gpio.html#ga0983906029818d8aa199b71b578d1c12" title="Read the input level of a GPIO pin.">nrf_gpio_pin_read</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga77ece330b6222b510f509e25282874b0">HR_INC_BUTTON_PIN_NO</a>) != 0)  <span class="comment">// If the button 0 is NOT pressed</span>
<a name="l01023"></a>01023         &amp;&amp;
<a name="l01024"></a>01024         (<a class="code" href="group__nrf__gpio.html#ga0983906029818d8aa199b71b578d1c12" title="Read the input level of a GPIO pin.">nrf_gpio_pin_read</a>(<a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5713bbcd7b63f0a3fa11eb22f08417ff">HR_DEC_BUTTON_PIN_NO</a>) != 0)  <span class="comment">// If the button 1 is NOT pressed</span>
<a name="l01025"></a>01025        )
<a name="l01026"></a>01026     {
<a name="l01027"></a>01027         is_startup_on_button_press = <span class="keyword">false</span>;
<a name="l01028"></a>01028     }
<a name="l01029"></a>01029 
<a name="l01030"></a>01030     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(); <span class="comment">// This is needed here because the nrf_power_system_off() that is called</span>
<a name="l01031"></a>01031                       <span class="comment">// in the code below needs the SoftDevice to be enabled.</span>
<a name="l01032"></a>01032 
<a name="l01033"></a>01033     <span class="keywordflow">if</span> (!is_startup_on_button_press)
<a name="l01034"></a>01034     {
<a name="l01035"></a>01035        <span class="comment">// The startup was not because of button presses. This is the first start.</span>
<a name="l01036"></a>01036        <span class="comment">// Go into System-Off mode.</span>
<a name="l01037"></a>01037         <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaff016ad71b5161ca8ad06bf590d973d4" title="Function to put the chip in System OFF Mode.">system_off_mode_enter</a>();
<a name="l01038"></a>01038     }
<a name="l01039"></a>01039 
<a name="l01040"></a>01040     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>();
<a name="l01041"></a>01041     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>();
<a name="l01042"></a>01042     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>();
<a name="l01043"></a>01043     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>();
<a name="l01044"></a>01044     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>();
<a name="l01045"></a>01045     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gacb0906fa1cb3aeed8e86dfdb6abdd5fd" title="Function to initalise the peripherals needed for generating PWM input to flash an LED...">pwm_config_init</a>();
<a name="l01046"></a>01046     adc_init();
<a name="l01047"></a>01047     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>();
<a name="l01048"></a>01048 
<a name="l01049"></a>01049     <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l01050"></a>01050     
<a name="l01051"></a>01051     <span class="comment">// Enter main loop</span>
<a name="l01052"></a>01052     <span class="keywordflow">for</span> (;;)
<a name="l01053"></a>01053     {
<a name="l01054"></a>01054         <a class="code" href="group__ble__sdk__app__hrs__eval__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>();
<a name="l01055"></a>01055     }
<a name="l01056"></a>01056 }
<a name="l01057"></a>01057 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="pca10001_2ble_2ble__app__hrs_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
